<!DOCTYPE html>
<html>
<!--
Copyright 2009 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by an Apache 2.0 License.
See the COPYING file for details.
-->
<!--
  Author: goto@google.com (Sam Goto)
-->
<head>
<title>Closure Unit Tests - goog.ui.media.Mp3</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.debug.Logger');
  goog.require('goog.dom');
  goog.require('goog.events');
  goog.require('goog.testing.jsunit');
  goog.require('goog.testing.LooseMock');
  goog.require('goog.ui.Component');
  goog.require('goog.ui.Control');
  goog.require('goog.ui.ControlRenderer');
  goog.require('goog.ui.media.FlashObject');
  goog.require('goog.ui.media.MediaModel');
  goog.require('goog.ui.media.MediaModel.Player');
  goog.require('goog.ui.media.Mp3');
  goog.require('goog.ui.media.Mp3Model');
</script>
</head>
<body>
<script>

  var mp3;
  var control;
  var MP3_URL = 'http://www.shellworld.net/~davidsky/surf-oxy.mp3';
  var parent = goog.dom.createElement('div');

  function setUp() {
    mp3 = goog.ui.media.Mp3.getInstance();
    var flashUrl = goog.ui.media.Mp3.buildFlashUrl(MP3_URL);
    var model = new goog.ui.media.MediaModel(MP3_URL, 'mp3 caption', '');
    model.setPlayer(new goog.ui.media.MediaModel.Player(flashUrl));
    control = new goog.ui.media.Media(model, mp3);
    control.setSelected(true);
  }

  function tearDown() {
    control.dispose();
  }

  function testBasicRendering() {
    control.render(parent);
    var el = goog.dom.getElementsByTagNameAndClass(
        'div', goog.ui.media.Mp3.CSS_CLASS, parent);
    assertEquals(1, el.length);
  }

  function testParsingUrl() {
    assertTrue(goog.ui.media.Mp3.MATCHER.test(MP3_URL));
    assertFalse(
        goog.ui.media.Mp3.MATCHER.test('http://invalidUrl/filename.doc'));
  }

  function testCreatingDomOnInitialState() {
    control.render(parent);
    var caption = goog.dom.getElementsByTagNameAndClass(
        'div',
        goog.ui.media.Mp3.CSS_CLASS + '-caption',
        parent);
    assertEquals(1, caption.length);

    var flash = goog.dom.getElementsByTagNameAndClass(
        undefined, goog.ui.media.FlashObject.CSS_CLASS, parent);
    assertEquals(1, flash.length);
  }
</script>
</body>
</html>
